/*************************************************************************
*																		 *
*		code by Miles Chen (stainboyx@hotmail.com) 2012.6.10			 *
*																		 *
*																		 *
*************************************************************************/

#include "StdAfx.h"
#include "MainForm.h"

CMainForm::CMainForm()
{
	this->IDD = IDD_FORM;
	this->m_nAppIconID = IDI_APP;
}

LRESULT CMainForm::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// TODO: Add your message handler code here and/or call default
	BOOL ret = CForm::OnInitDialog(uMsg, wParam, lParam, bHandled);

	// Append a sub-menu "About" to system menu
	HMENU hMenu = GetSystemMenu(FALSE);
	AppendMenuW(hMenu, MF_ENABLED | MF_STRING, IDM_ABOUT, L"&About");

	this->m_pSpy = new CSpyCab();
	this->m_pSpy->InitSpy(this->m_hWnd, this->m_hAppIcon, 
		IDC_SPY_HWND, 
		IDC_SPY_PID, 
		IDC_SPY_ID, 
		IDC_SPY_CAPTION, 
		IDC_SPY_CLASS, 
		IDC_SPY);

	return ret;
}

LRESULT CMainForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// TODO: Add your message handler code here and/or call default
	delete this->m_pSpy;

	return CForm::OnClose(uMsg, wParam, lParam, bHandled);
}

LRESULT CMainForm::OnLButtonUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// TODO: Add your message handler code here and/or call default
	this->m_pSpy->OnSpyFinish();

	return 0;
}

LRESULT CMainForm::OnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// TODO: Add your message handler code here and/or call default
	this->m_pSpy->OnSpySearching();

	return 0;
}

//LRESULT CMainForm::OnBnClickedCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//{
//	// TODO: Add your control notification handler code here
//	ShellExecuteW(NULL, NULL, L"cmd", NULL, NULL, SW_SHOW);
//
//	return 0;
//}
//
//LRESULT CMainForm::OnBnClickedReg(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//{
//	// TODO: Add your control notification handler code here
//
//	// unlock registry
//	HKEY hKey;
//	LONG ls;
//	ls = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_ALL_ACCESS, &hKey );
//	if(ls == ERROR_SUCCESS)
//	{
//		DWORD dwVaule = 0;
//		ls = RegSetValueExW(hKey, L"DisableRegistryTools", NULL, REG_DWORD, (BYTE*)&dwVaule, sizeof(DWORD));
//		ls = RegCloseKey(hKey);
//	}
//
//	// Add additional code here
//	ShellExecuteW(NULL, NULL, L"regedit", NULL, NULL, SW_SHOW);
//
//	return 0;
//}
//
//LRESULT CMainForm::OnBnClickedWin(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//{
//	// TODO: Add your control notification handler code here
//
//	//in XP, show and enable 'Win' key
//	HWND trayWnd = FindWindowW(L"Shell_TrayWnd", NULL);
//	HWND hWin = ::GetWindow(trayWnd, GW_CHILD);
//	::ShowWindow(hWin, SW_SHOW);
//	::EnableWindow(hWin, TRUE);
//
//	//click 'Win' key
//	this->SendMessageW(WM_SYSCOMMAND, SC_TASKLIST);
//
//	return 0;
//}
//
//LRESULT CMainForm::OnBnClickedMail(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//{
//	// TODO: Add your control notification handler code here
//
//	OnMailWalkthrough(this->m_hWnd);
//
//	return 0;
//}
//
//LRESULT CMainForm::OnBnClickedNotepad(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//{
//	// TODO: Add your control notification handler code here
//
//	ShellExecuteW(NULL, NULL, L"notepad", NULL, NULL, SW_SHOW);
//
//	return 0;
//}

LRESULT CMainForm::OnStnClickedSpy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: Add your control notification handler code here
	this->m_pSpy->OnSpyStart();

	return 0;
}

LRESULT CMainForm::OnCtlColorDlg(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	return CForm::OnCtlColorDlg(uMsg, wParam, lParam, bHandled);
}

LRESULT CMainForm::OnCtlColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	return CForm::OnCtlColorStatic(uMsg, wParam, lParam, bHandled);
}

LRESULT CMainForm::OnMenuClickedAbout(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	CString szStuff = L"NetShare v2 ("
#ifdef _M_X64
	L"x64"
#else
	L"x86"
#endif
	L"), Powered by Visual Studio 2012 (Target vc10)\r\nCompiled at ";

	szStuff += __DATE__;
	szStuff += L" ";
	szStuff += __TIME__;


	return MessageBox(szStuff, L"About", MB_OK | MB_ICONINFORMATION);
}
